package com.yanqu.road.server.cmd.activity.dragonboatrace;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.logic.pb.CrossUnionPb;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.pb.dragonboatrace.DragonBoatRaceProto;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.dragonboatrace.DragonBoatRaceMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

/**
 * @Description
 * @Author cwq
 * @Data 2022/2/15 16:56
 */
@Cmd(code = CrossProtocol.C2_DRAGONBOATRACE_ADD_VOYAGE_RECORD, desc = "赛龙舟 添加联盟成员 航行记录")
public class CrossDragonBoatRaceAddVoyageRecordCmd extends CrossCommand {

    int activityId;
    String unionId;
    long userId;
    long distance;
    long cutTime;
    UnionBaseInfo unionBase;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DragonBoatRaceProto.DragonBoatRaceAddVoyageRecordGameToCrossMsg builder = DragonBoatRaceProto.DragonBoatRaceAddVoyageRecordGameToCrossMsg.parseFrom(packet.getBytes());
        activityId = builder.getActivityId();
        unionId = builder.getUnionId();
        userId = builder.getUserId();
        distance = builder.getRealDistance();
        cutTime = builder.getCutTime();
        unionBase = UnionBasePb.parseUnionBaseInfo(builder.getUnionBase());
        // 更新玩家信息
        if (builder.hasUserInfo()) {
            CrossUserMgr.updateUserBaseInfo(userId, PlayerBasePb.parseToUserBaseInfo(builder.getUserInfo()));
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DragonBoatRaceMgr.addDragonBoatRaceVoyageRecord(activityId, unionId, userId, distance, cutTime, unionBase);

    }

    @Override
    public void sendData() {

    }
}
